System Startup va Boot Process
Linux tizimining boot process'i - bu kompyuter yoqilgandan to ishlaydigan holatga kelishigacha bo'lgan murakkab jarayon. Bu jarayonni tushunish system administration va troubleshooting uchun juda muhim.
Boot Process Overview
Boot Sequence Bosqichlari
1. BIOS/UEFI Power-On Self Test (POST)
2. Bootloader (GRUB/LILO) loading
3. Kernel loading va initialization
4. initramfs/initrd execution
5. Root filesystem mounting
6. Init system startup (systemd/SysV)
7. Services va applications startup
8. User login
Boot Process Timeline
# Boot process vaqtini ko'rish
systemd-analyze # Boot time summary
systemd-analyze blame # Service startup times
systemd-analyze critical-chain # Critical path
systemd-analyze plot > boot.svg # Boot process visualization
BIOS/UEFI Stage
BIOS vs UEFI
# Boot mode aniqlash
[ -d /sys/firmware/efi ] && echo "UEFI" || echo "BIOS"
# UEFI ma'lumotlari (UEFI system'da)
efibootmgr -v # UEFI boot entries
ls -la /sys/firmware/efi/efivars # EFI variables
# BIOS ma'lumotlari
sudo dmidecode -t bios # BIOS information
sudo dmidecode -t system # System information
Hardware Initialization
# Hardware detection logs
dmesg | head -50 # Kernel boot messages
dmesg | grep -i "detected\|found" # Hardware detection
lspci # PCI devices
lsusb # USB devices
lscpu # CPU information
lsblk # Block devices
Bootloader (GRUB)
GRUB Configuration
# GRUB configuration files
cat /etc/default/grub # GRUB defaults
ls -la /etc/grub.d/ # GRUB configuration scripts
cat /boot/grub/grub.cfg # Generated GRUB config (don't edit)
# GRUB configuration update
sudo update-grub # Ubuntu/Debian
sudo grub2-mkconfig -o /boot/grub2/grub.cfg # CentOS/RHEL
GRUB Menu Management
# GRUB default settings
GRUB_DEFAULT=0 # Default menu entry
GRUB_TIMEOUT=10 # Menu timeout
GRUB_HIDDEN_TIMEOUT=0 # Hidden timeout
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" # Kernel parameters
# GRUB menu entries
grep "menuentry" /boot/grub/grub.cfg # Available menu entries
sudo grub-set-default 0 # Set default entry
# Custom GRUB entries
sudo vim /etc/grub.d/40_custom # Custom menu entries
# Example:
menuentry "Custom Linux" {
set root=(hd0,1)
linux /vmlinuz root=/dev/sda1
initrd /initrd.img
}
GRUB Troubleshooting
# GRUB recovery
# Boot'dan GRUB menu'da:
# 1. Advanced options
# 2. Recovery mode
# 3. Root shell
# GRUB reinstall
sudo grub-install /dev/sda # Install GRUB to disk
sudo update-grub # Update configuration
# GRUB rescue mode
# grub rescue> prompt'da:
set root=(hd0,1)
linux /vmlinuz root=/dev/sda1
initrd /initrd.img
boot
Kernel Loading
Kernel Files
# Kernel files location
ls -la /boot/ # Boot directory
ls -la /boot/vmlinuz* # Kernel images
ls -la /boot/initrd.img* # Initial ramdisk
ls -la /boot/System.map* # Kernel symbol table
ls -la /boot/config-* # Kernel configuration
# Current kernel
uname -r # Kernel version
uname -a # Full system information
cat /proc/version # Kernel version details
Kernel Parameters
# Current kernel parameters
cat /proc/cmdline # Boot-time kernel parameters
# Common kernel parameters
quiet # Suppress boot messages
splash # Show splash screen
ro # Read-only root filesystem
root=/dev/sda1 # Root filesystem
init=/sbin/init # Init process
systemd.unit=rescue.target # Boot to rescue mode
single # Single user mode
# Temporary kernel parameters (GRUB menu'da)
# 'e' tugmasini bosib kernel line'ga parameter qo'shish
Kernel Modules
# Module management
lsmod # Loaded modules
modinfo module_name # Module information
sudo modprobe module_name # Load module
sudo modprobe -r module_name # Unload module
# Module configuration
cat /etc/modules # Modules to load at boot
ls /etc/modprobe.d/ # Module configuration
cat /proc/modules # Loaded modules details
# Module blacklisting
echo "blacklist module_name" | sudo tee -a /etc/modprobe.d/blacklist.conf
initramfs/initrd
initramfs Basics
# initramfs files
ls -la /boot/initrd.img* # initramfs images
file /boot/initrd.img-$(uname -r) # File type
# initramfs contents
sudo mkdir /tmp/initramfs
cd /tmp/initramfs
sudo zcat /boot/initrd.img-$(uname -r) | sudo cpio -idmv # Extract
# initramfs structure
bin/ # Essential binaries
sbin/ # System binaries
etc/ # Configuration
lib/ # Libraries
usr/ # User binaries
sys/ # sysfs mount point
proc/ # procfs mount point
dev/ # Device files
init # Init script
initramfs Management
# Rebuild initramfs
sudo update-initramfs -u # Update current kernel
sudo update-initramfs -c -k $(uname -r) # Create for current kernel
sudo update-initramfs -u -k all # Update all kernels
# Dracut (alternative)
sudo dracut --force # Regenerate initramfs
sudo dracut --kver $(uname -r) # For specific kernel
# mkinitcpio (Arch Linux)
sudo mkinitcpio -g /boot/initramfs-linux.img # Generate
sudo mkinitcpio -P # All presets
Root Filesystem Mounting
Filesystem Table
# /etc/fstab - Filesystem table
cat /etc/fstab
# Format: device mountpoint filesystem options dump pass
# Example fstab entry:
UUID=12345678-1234-1234-1234-123456789012 / ext4 defaults 0 1
UUID=87654321-4321-4321-4321-210987654321 /home ext4 defaults 0 2
/dev/sda3 swap swap defaults 0 0
# fstab validation
sudo mount -a # Mount all fstab entries
findmnt --verify # Verify fstab syntax
Filesystem Mounting Process
# Mount information
mount # Currently mounted filesystems
cat /proc/mounts # Kernel view of mounts
findmnt # Tree view of mounts
findmnt / # Specific mount point
# UUID and labels
blkid # Block device UUIDs and labels
lsblk -f # Filesystem information
sudo blkid /dev/sda1 # Specific device UUID
Emergency Filesystem Repair
# Filesystem check and repair
sudo fsck /dev/sda1 # Check filesystem
sudo fsck -y /dev/sda1 # Auto-repair
sudo e2fsck -f /dev/sda1 # Force check (ext2/3/4)
# Emergency read-only remount
sudo mount -o remount,ro / # Remount root as read-only
sudo mount -o remount,rw / # Remount as read-write
# Recovery mode mounting
mkdir /mnt/recovery
sudo mount /dev/sda1 /mnt/recovery # Mount for recovery
Init System (systemd)
systemd Boot Targets
# Boot targets (runlevels)
systemctl get-default # Default target
systemctl list-units --type=target # Available targets
# Common targets:
poweroff.target # Shutdown (runlevel 0)
rescue.target # Single user (runlevel 1)
multi-user.target # Multi-user console (runlevel 3)
graphical.target # Multi-user GUI (runlevel 5)
reboot.target # Reboot (runlevel 6)
emergency.target # Emergency shell
# Target management
sudo systemctl set-default multi-user.target # Set default
sudo systemctl isolate rescue.target # Switch target
systemd Boot Analysis
# Boot performance analysis
systemd-analyze # Boot time summary
systemd-analyze time # Detailed timing
systemd-analyze blame # Service startup times
systemd-analyze critical-chain # Critical path analysis
# Service dependencies
systemd-analyze plot > boot.svg # SVG plot
systemd-analyze dot | dot -Tsvg > dependencies.svg # Dependency graph
# Boot messages
journalctl -b # Current boot logs
journalctl -b -1 # Previous boot logs
journalctl --list-boots # Available boot logs
systemd Configuration
# systemd configuration
cat /etc/systemd/system.conf # Main configuration
ls /etc/systemd/system/ # Custom unit files
ls /lib/systemd/system/ # System unit files
# Service dependencies
systemctl list-dependencies graphical.target # Target dependencies
systemctl show -p Wants,Requires,After,Before service_name
Boot Troubleshooting
Common Boot Issues
# Boot problems diagnostics
# 1. GRUB issues
# - GRUB rescue prompt
# - Missing boot menu
# - Kernel panic
# 2. Kernel issues
# - Kernel panic
# - Module loading problems
# - Hardware detection failures
# 3. Filesystem issues
# - Corrupt filesystem
# - Wrong UUID in fstab
# - Mount failures
# 4. Init system issues
# - Service failures
# - Dependency problems
# - Configuration errors
Boot Logs Analysis
# Boot messages
dmesg # Kernel messages
journalctl -b # systemd boot logs
cat /var/log/boot.log # Boot log (if available)
# Specific boot stages
journalctl -u systemd-modules-load # Module loading
journalctl -u systemd-fsck@* # Filesystem checks
journalctl -u local-fs.target # Local filesystem
journalctl -u network.target # Network services
# Boot failures
journalctl -p err -b # Error messages
journalctl --failed # Failed services
systemctl --failed # Failed units
Recovery Procedures
# Single user mode
# GRUB menu'da kernel line'ga qo'shish:
single
# yoki
systemd.unit=rescue.target
# Emergency mode
# GRUB menu'da:
systemd.unit=emergency.target
# Recovery from live CD/USB
mkdir /mnt/system
sudo mount /dev/sda1 /mnt/system # Mount root
sudo mount /dev/sda2 /mnt/system/boot # Mount boot (if separate)
sudo chroot /mnt/system # Change root
# In chroot environment:
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t devtmpfs devtmpfs /dev
# Now you can repair system
Custom Boot Scripts
systemd Service for Boot
# Custom boot service
sudo vim /etc/systemd/system/custom-boot.service
[Unit]
Description=Custom Boot Script
After=multi-user.target
Wants=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/custom-boot.sh
RemainAfterExit=yes
TimeoutStartSec=300
[Install]
WantedBy=multi-user.target
# Enable service
sudo systemctl enable custom-boot.service
Boot Time Script
#!/bin/bash
# custom-boot.sh - Custom boot initialization
LOG_FILE="/var/log/custom-boot.log"
log_message() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
}
# Boot-time system checks
check_system() {
log_message "Starting custom boot checks..."
# Check disk space
disk_usage=$(df / | awk 'NR==2 {print $5}' | sed 's/%//')
if [ "$disk_usage" -gt 90 ]; then
log_message "WARNING: Root filesystem is ${disk_usage}% full"
fi
# Check memory
mem_available=$(free | awk 'NR==2{printf "%.1f", $7/$2*100}')
log_message "Available memory: ${mem_available}%"
# Check services
critical_services=("ssh" "network" "systemd-logind")
for service in "${critical_services[@]}"; do
if systemctl is-active "$service" >/dev/null; then
log_message "OK: $service is running"
else
log_message "ERROR: $service is not running"
fi
done
# Set system-specific configurations
log_message "Applying system configurations..."
# Example: Set performance governor for servers
if [ -f /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ]; then
echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
log_message "Set CPU governor to performance"
fi
# Example: Configure network parameters
echo 'net.core.rmem_max = 16777216' | sudo tee -a /etc/sysctl.conf
echo 'net.core.wmem_max = 16777216' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
log_message "Applied network optimizations"
log_message "Custom boot checks completed"
}
# Execute checks
check_system
GRUB Custom Menu
# Custom GRUB menu entry
sudo vim /etc/grub.d/40_custom
#!/bin/sh
exec tail -n +3 $0
menuentry "System Maintenance Mode" {
set root=(hd0,1)
linux /vmlinuz root=/dev/sda1 systemd.unit=rescue.target
initrd /initrd.img
}
menuentry "Memory Test" {
set root=(hd0,1)
linux16 /memtest86+.bin
}
menuentry "Previous Kernel" {
set root=(hd0,1)
linux /vmlinuz.old root=/dev/sda1 ro quiet
initrd /initrd.img.old
}
# Update GRUB
sudo update-grub
Boot Performance Optimization
Boot Time Analysis
#!/bin/bash
# boot-analysis.sh - Boot performance analysis
echo "=== Boot Performance Analysis ==="
echo "Date: $(date)"
echo
# Overall boot time
echo "=== Boot Time Summary ==="
systemd-analyze
echo -e "\n=== Longest Starting Services ==="
systemd-analyze blame | head -20
echo -e "\n=== Critical Chain ==="
systemd-analyze critical-chain
echo -e "\n=== Service Status ==="
failed_services=$(systemctl --failed --no-legend | wc -l)
echo "Failed services: $failed_services"
if [ "$failed_services" -gt 0 ]; then
echo "Failed services list:"
systemctl --failed --no-legend
fi
echo -e "\n=== Boot Messages Analysis ==="
error_count=$(journalctl -b | grep -i error | wc -l)
warning_count=$(journalctl -b | grep -i warning | wc -l)
echo "Boot errors: $error_count"
echo "Boot warnings: $warning_count"
if [ "$error_count" -gt 0 ]; then
echo -e "\nRecent boot errors:"
journalctl -b | grep -i error | tail -5
fi
echo -e "\n=== System Info ==="
echo "Kernel: $(uname -r)"
echo "Init system: $(ps --no-headers -o comm 1)"
echo "Boot ID: $(journalctl --list-boots | head -1 | awk '{print $2}')"
Boot Optimization Tips
# Disable unnecessary services
sudo systemctl disable bluetooth
sudo systemctl disable cups
sudo systemctl disable avahi-daemon
# Parallel service startup (already default in systemd)
# Check service dependencies
systemctl list-dependencies --all
# Reduce GRUB timeout
sudo sed -i 's/GRUB_TIMEOUT=.*/GRUB_TIMEOUT=2/' /etc/default/grub
sudo update-grub
# Use faster filesystem options
# In /etc/fstab:
# /dev/sda1 / ext4 defaults,noatime 0 1
# Disable unnecessary kernel modules
echo "blacklist floppy" | sudo tee -a /etc/modprobe.d/blacklist.conf
# Use systemd-analyze to find bottlenecks
systemd-analyze plot > boot-analysis.svg
Emergency Boot Preparation
#!/bin/bash
# emergency-boot-prep.sh - Prepare for emergency boot scenarios
# Create emergency boot kit
mkdir -p /boot/emergency
# Backup critical configuration files
backup_configs() {
configs=(
"/etc/fstab"
"/etc/default/grub"
"/boot/grub/grub.cfg"
"/etc/systemd/system.conf"
"/etc/modules"
"/etc/modprobe.d/"
)
for config in "${configs[@]}"; do
if [ -e "$config" ]; then
cp -r "$config" /boot/emergency/
fi
done
}
# Create recovery script
cat << 'EOF' > /boot/emergency/recovery.sh
#!/bin/bash
# Emergency recovery script
echo "=== Emergency Recovery Mode ==="
echo "Available commands:"
echo "1. mount -o remount,rw / # Remount root as read-write"
echo "2. fsck /dev/sda1 # Check root filesystem"
echo "3. systemctl rescue # Enter rescue mode"
echo "4. journalctl -xe # View system logs"
echo "5. systemctl --failed # List failed services"
# Quick system check
echo -e "\n=== Quick System Check ==="
echo "Root filesystem:"
df -h / 2>/dev/null || echo "Cannot check root filesystem"
echo "Memory:"
free -h 2>/dev/null || echo "Cannot check memory"
echo "Failed services:"
systemctl --failed --no-legend 2>/dev/null || echo "Cannot check services"
EOF
chmod +x /boot/emergency/recovery.sh
# Document recovery procedures
cat << 'EOF' > /boot/emergency/RECOVERY_GUIDE.txt
Emergency Boot Recovery Guide
============================
1. GRUB Issues:
- Boot from live CD/USB
- Mount root filesystem: mount /dev/sda1 /mnt
- Reinstall GRUB: grub-install --root-directory=/mnt /dev/sda
- Update config: chroot /mnt && update-grub
2. Kernel Panic:
- Boot previous kernel from GRUB menu
- Check /var/log/kern.log for errors
- Rebuild initramfs: update-initramfs -u
3. Filesystem Corruption:
- Boot from live CD/USB
- Run fsck: fsck /dev/sda1
- Check fstab: cat /etc/fstab
4. systemd Issues:
- Boot to rescue mode: systemd.unit=rescue.target
- Check failed services: systemctl --failed
- View logs: journalctl -xe
5. Emergency Contact:
- System Administrator: admin@company.com
- Emergency Phone: +1-555-0123
EOF
echo "Emergency boot preparation completed"
echo "Files created in /boot/emergency/"
backup_configs
Bu tutorial system startup va boot process haqida to'liq ma'lumot beradi - BIOS/UEFI dan tortib user login gacha bo'lgan barcha bosqichlar, troubleshooting va optimization texnikalari bilan birga.